package main

import "fmt"

//基本函数 单个返回值
func f001(a string, b int) int {
	//fmt.Println("a = ", a)
	//fmt.Println("b = ", b)
	return 2
}

//返回多个返回值，匿名的返回值
func f002(a string, b int) (int, int) {
	//fmt.Println("a = ", a)
	//fmt.Println("b = ", b)
	return 2, 3
}

//返回多个返回值， 有形参名称的
func foo3(a string, b int) (a1 int, a2 int) {
	fmt.Println("---- foo3 ----")
	//r1 r2 属于foo3的形参，  初始化默认的值是0
	//r1 r2 作用域空间 是foo3 整个函数体的{}空间
	fmt.Println("r1 = ", a1)
	fmt.Println("r2 = ", a2)
	a1 = 100
	a2 = 100
	return
}

//r1, r2  都是 int 类型的值
func foo4(a string, b int) (r1, r2 int) {
	fmt.Println("---- foo4 ----")
	fmt.Println("a = ", a)
	fmt.Println("b = ", b)

	//给有名称的返回值变量赋值
	r1 = 1000
	r2 = 2000

	return
}

func main() {

	c := f001("333", 222)
	fmt.Println(c)

	ret1, ret2 := f002("23", 22)
	fmt.Println(ret1, ret2)
	fmt.Println(ret1 + ret2)

	ret1, ret2 = foo3("foo3", 333)
	fmt.Println("ret1 = ", ret1, " ret2 = ", ret2)

	ret1, ret2 = foo4("foo4", 444)
	fmt.Println("ret1 = ", ret1, " ret2 = ", ret2)
}
